﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using EnvironmentalMonitor.Support.Business.Manage;
using EnvironmentalMonitor.Support.Business;
using EnvironmentalMonitor.Support.Module.Manage;
using EnvironmentalMonitor.Support.Module;
using EnvironmentalMonitor.Support.Resource;

namespace EnvironmentalMonitor.WebApplication.Abstract
{
    /// <summary>
    /// 安全页面类
    /// </summary>
    public abstract class AbstractSecurityPage : EnvironmentalMonitor.WebApplication.Abstract.AbstractPage
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            bool login = false;

            User user = this.Session[Constant.SESSION_KEY_USER] as User;
            if (user != null)
            {
                if ((user.Authentication) || (user.Prerogative))
                {
                    login = true;
                }
            }

            if (!login)
            {
                this.Response.Redirect(string.Format("{0}Manage/User/Logout.aspx", EnvironmentalMonitor.Support.Resource.Variable.VirtualRootPath));
            }
            else
            {
                Type pageType = this.GetType();
                UserBusiness business = new UserBusiness();
                bool allow = business.VerifyPage(user, pageType);

                allow = true;

                if (!allow)
                {
                    this.Response.Redirect(string.Format("{0}Manage/User/Verify.aspx", EnvironmentalMonitor.Support.Resource.Variable.VirtualRootPath));
                }
            }
        }
    }
}